home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / NTUMIN10.ARJ / FPRTIN.C < prev    next >
C/C++ Source or Header  |  1992-03-12  |  2KB  |  71 lines

  1. /****************************************************************************
  2.  *
  3.  *      Program name : FPRTIN.C
  4.  *
  5.  *    Written By : Eng-Huat Ong and Kian-Mong Low.
  6.  *
  7.  *      This program reads the ON and DC arrays from the input data file and
  8.  *      writes them to the output file.
  9.  *
  10.  * --------------------------------------------------------------------------
  11.  *    Copyright (c) 1992. All Rights Reserved. Nanyang Technological
  12.  *    University.
  13.  *
  14.  *    You are free to use, copy and distribute this software and its
  15.  *    documentation providing that:
  16.  *
  17.  *        NO FEE IS CHARGED FOR USE, COPYING OR DISTRIBUTION.
  18.  *
  19.  *        IT IS NOT MODIFIED IN ANY WAY.
  20.  *
  21.  *        THE COPYRIGHT NOTICE APPEAR IN ALL COPIES.
  22.  *
  23.  *    This program is provided "AS IS" without any warranty, expressed or
  24.  *    implied, including but not limited to fitness for any particular
  25.  *    purpose.
  26.  *
  27.  *    If you find NTUMIN fast, easy, and useful, a note or comment would be
  28.  *    appreciated. Please send to:
  29.  *
  30.  *        Boon-Tiong Tan or Othman Bin Ahmad
  31.  *        School of EEE
  32.  *        Nanyang Technological University
  33.  *        Nanyang Avenue
  34.  *        Singapore 2263
  35.  *        Republic of Singapore
  36.  *
  37.  ***************************************************************************/
  38.  
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41.  
  42. void           fprtin(in, out, ondc)
  43. unsigned char  ondc;
  44. FILE           *in, *out;
  45.  
  46. {
  47.    unsigned short  i=0, p;
  48.    unsigned char   n, *cube;
  49.  
  50.  
  51.    if (ondc==0)                                        /* ON array */
  52.       fscanf(in, "%d", &n);                            /* no. of variables */
  53.  
  54.    fscanf(in, "%d", &p);                         /* no. of cubes */
  55.  
  56.    cube = (unsigned char *) malloc(n+1);               /* space for cube + 1 */
  57.    if (cube==0)
  58.       {
  59.      printf("Out of memory -- FPRTIN, *cube\n");
  60.      printf("Program terminated - 1\n");
  61.      exit(0);
  62.       }
  63.  
  64.    while (++i <= p)                                     /* copy all cubes  */
  65.       {                                                 /*                 */
  66.      fscanf(in, "%s", cube);                        /* from input file */
  67.      fprintf(out, "%s\n", cube);                    /*                 */
  68.       }                                                 /* to output file  */
  69.    free(cube);                                          /* free pointer    */
  70. }
  71.